import { DialogForm } from 'custom/index'
import { resumeCooperation, getUserList, updateStopShopInfo, currentCompanyDeptPage, getDepartment } from '../api'

const realReasonList = [
  { label: '高标服务流失', value: '高标服务流失' },
  { label: '常规服务流失', value: '常规服务流失' },
  { label: '自然流失', value: '自然流失' }
]

const recoveryResultList = [
  { label: '成功', value: '成功' },
  { label: '失败', value: '失败' }
]

const recoveryDialog = new DialogForm('DialogForm')

recoveryDialog
  .title('恢复合作')
  .getApi(async (_, row) => ({ shopId: row.shopId }))
  .postApi(resumeCooperation)
  .useGroup('')
    .useDatePicker('startDate').label('开始日期').required().end()
    .useDatePicker('endDate').label('截止日期').required().end()
    .useItem('remark').label('备注').setProps({ type: 'textarea', autosize: true }).end()

const editDialog = new DialogForm('DialogForm')
editDialog.title('编辑')
  .getApi(async(_, row) => {
    const data = { ...row }
    if (!row.stopUserDept) {
      const list = await getDepartment()
      const d = list[0] || {}
      data.stopUserDept = data.stopUserDept || d.val
    }
    return data
  })
  .postApi(updateStopShopInfo)
  .useGroup('')
    .useApiSelect('stopUserId', currentCompanyDeptPage).setProp('valueKey', 'userId').setProp('labelKey', 'name').label('判定员').end()
    .useApiSelect('stopUserDept', getDepartment).label('判定员部门').setProp('valueKey', 'val').setProp('labelKey', 'name').setProp('widthLabel', 'stopUserDeptName').end()
    .useSelect('realReason', realReasonList).label('真实原因').end()
    .useItem('judgeReason').label('业务流失信息判定').end()
    .useSelect('recoveryResult', recoveryResultList).label('客户挽回结果').end()

export { recoveryDialog, editDialog }
